#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
@Author   : long.hai
@Contact  : 1982964634@qq.com
"""
import re


class BaseError(Exception):
    _info = None

    def __init__(self, ErrorInfo=None):
        self._info = ErrorInfo or self._info

    def __str__(self):
        return self._info


class ConnectError(BaseError):
    _info = '连接浏览器失败。\n'


class WaitTimeoutError(BaseError):
    _info = '等待超时异常。\n'


class DOMError(BaseError):

    def __init__(self, message):
        _info = '元素定位不符合规范。\n'
        if 'valid XPath' in message:
            match = re.search(r'The string(.*?)is not', message)
            if match:
                # 提取匹配结果
                _info = f"元素不是有效的XPath表达式: {match.group(1)}"
        super().__init__(_info)


class AssertError(BaseError):
    _info = '断言失败。\n'
